function validar() {
	try {
		var f = document.getElementById("editarform");

		var callback = new Z.JsonCall();
		callback.exito = function(data) {
			
			procesa();
			Context.dialog1.hide();
			
		};
		
		Y.util.Connect.setForm(f);
		
		var request = Y.util.Connect.asyncRequest('POST', Context.ValidarURL, callback);

	} catch (e) {
		alert("validar: " + e + e.description);
	}
};

function procesa() {
	try {
		var nuevo = Dom.get("nuevo").value;
		var oData = {};
		Dom = Y.util.Dom;
		
		oData['recordid'] = Dom.get("recordid").value;
		oData['idConnection'] = Dom.get("idConnection").value;
		oData['idCountry'] = Dom.get("idCountry").value;
		oData['descCountry'] = Dom.get("idCountry").options[Dom.get("idCountry").selectedIndex].text;
		oData['username'] = Dom.get("username").value;
		oData['password'] = Dom.get("password").value;
		oData['url'] = Dom.get("url").value;
		oData['vigente'] = Dom.get("vigente").value;
		oData['nuevo'] = nuevo;
		oData['eliminado'] = false;
		if(nuevo == true || nuevo=="true"){
			
			myDataTable.insertarRegistro(oData);
		}else{
			myDataTable.actualizarRegistro(oData);
		}
		
	} catch (e) {
		alert("procesa : " + e.description + " " + e.message)
	}
	
}

function creardialogo() {
	Context.dialog1 = new Y.widget.Dialog("dialog1", {
		width : "30em",
		
		fixedcenter : true,
		visible : false,
		constraintoviewport : true,
		modal : true,
		zindex : 5,
		buttons : [ {
			text : "Aceptar",
			handler : function(){
				validar();
			},
			isDefault : true
		}, {
			text : "Cancelar",
			handler : function(){
				Context.dialog1.hide();
			}
		} ]
	});
	var kw = new Y.util.KeyListener(document, {
		keys : 27
	}, {
		fn : Context.dialog1.hide,
		scope : Context.dialog1,
		correctScope : true
	});
	kw.enable();
	Context.dialog1.render(document.body);
	
}

function crearbotones() {


	new Y.widget.Button("guardarbutton", {
		onclick : {
			fn : function() {
				//guardarUsuarios();
			}
		}
	});
	
	new Y.widget.Button("agregarbutton", {
		onclick : {
			fn : function() {
				var f = document.getElementById("editarform");
		    	Z.ClearForm(f); 
		    	Dom.get("idConnection").disabled=false;
				Dom.get("nuevo").value=true;
				Dom.get("idCountry").disabled=false;
				Context.dialog1.setHeader("Agregar");
				Context.dialog1.show();
			}
		}
	});
	

};



Y.util.Event.onDOMReady(function() {
	try {
		creardialogo();
		crearbotones();
		creardatatable();
		Context.table.update();
	} catch (e) {
		alert(e);
	}
});